package com.estronger.shopmanage.ui.order.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.estronger.shopmanage.R;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017-08-10.
 */

public class ShowImagesAdapter  extends BaseAdapter{

    protected Context context;
    protected LayoutInflater inflater;
    protected List<String> myList = new ArrayList<String>();

    public ShowImagesAdapter(Context context,List<String> mList) {
        this.context = context;
        this.inflater =LayoutInflater.from(context);
        myList = mList;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        if(myList ==null){
            return 0;
        }
        return myList.size();
    }

    @Override
    public String getItem(int position) {
        // TODO Auto-generated method stub
        if(myList ==null||myList.size()<=0){
            return null;
        }
        if(position>myList.size()){
            return null;
        }
        return myList.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        String bitPath = myList.get(position);
        ViewHolder vh = null;
        if (convertView == null) {
            convertView = inflater.inflate(
                    R.layout.view_detailbitmap, parent, false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }
        try {
            //加载图片
//            String purl = MyApplication.getApplication().getSERVER_URL()
//                    + "/web/common/Handler/file_download.ashx?filepath=" + bitPath;
            Picasso.with(context).load(bitPath).placeholder(R.drawable.no_picture_icon).
                    error(R.drawable.no_picture_icon).into(vh.imgf);
        }catch (Exception e){}
        return convertView;
    }
    class ViewHolder{
        private ImageView imgf;
        public ViewHolder(View view){
            this.imgf = (ImageView) view.findViewById(R.id.imgfCpBitmap);
        }
    }

}